package com.chao.wind3j.controller;

import com.chao.wind3j.base.apiResult.ApiResult;
import com.chao.wind3j.base.config.commonConfig.pageConfig.NeedCommonPage;
import com.chao.wind3j.base.config.dozerConfig.CastBean;
import com.chao.wind3j.model.base.pageVo.WPage;
import com.chao.wind3j.model.dataBaseModel.Wind3Test;
import com.chao.wind3j.model.dataVo.Wind3TestVo;
import com.chao.wind3j.model.searchParams.TestParams.Wind3TestAddRequest;
import com.chao.wind3j.model.searchParams.TestParams.Wind3TestParams;
import com.chao.wind3j.model.searchParams.TestParams.Wind3TestUpdateRequest;
import com.chao.wind3j.service.Wind3TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("testController")
@RequestMapping("/test")
public class TestController {

    @Autowired
    private CastBean castBean;

    @Autowired
    private Wind3TestService wind3TestService;

    @GetMapping("/getTestList")
    @NeedCommonPage
    public ApiResult<List<Wind3TestVo>> getTestList(Wind3TestParams wind3TestParams, WPage wpage) {
        var searchParams = this.castBean.castModelToVo(wind3TestParams, Wind3Test.class);
        var list = this.wind3TestService.getWind3TestList(searchParams);
        var finalList = this.castBean.castModelToVo(list, Wind3TestVo.class);
        return ApiResult.success(finalList);
    }

    @PostMapping("/insertTest")
    public ApiResult<Boolean> insertTestVo(@RequestBody Wind3TestAddRequest wind3TestAddRequest) {
        var addParams = this.castBean.castModelToVo(wind3TestAddRequest, Wind3Test.class);
        this.wind3TestService.insertWind3Test(addParams);
        return ApiResult.success(true);
    }

    @PostMapping("/updateTest")
    public ApiResult<Boolean> updateTestVo(@RequestBody Wind3TestUpdateRequest wind3TestUpdateRequest) {
        var updateParams = this.castBean.castModelToVo(wind3TestUpdateRequest, Wind3Test.class);
        this.wind3TestService.updateWind3Test(updateParams);
        return ApiResult.success(true);
    }

    @GetMapping("/getById")
    public ApiResult<Wind3TestVo> getWind3TestById(String testId){
        var wind3Test = this.wind3TestService.getWind3TestById(testId);
        var resultData = this.castBean.castModelToVo(wind3Test, Wind3TestVo.class);
        return ApiResult.success(resultData);
    }
}
